home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Formatter.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _Formatter_
- #define _Formatter_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _Array_
- #include "Array.h"
- #endif
-
- #ifndef _RunsRanges_
- #include "RunsRanges.h"
- #endif
-
- #ifndef _Frames_
- #include "Frames.h"
- #endif
-
- #ifdef txtnRulers
- #ifndef _RulersRanges_
- #include "RulersRanges.h"
- #endif
-
- #ifndef _RulerObject_
- #include "RulerObject.h"
- #endif
- #endif
-
- #ifndef _ObjectsRanges_
- #include "ObjectsRanges.h"//for CRanges
- #endif
-
- #ifndef _StyledText_
- #include "StyledText.h"
- #endif
-
- //***************************************************************************************************
-
- struct TLineInfo{
- long lineEnd;
- TLineHiteInfo lineHiteInfo;
- };
- typedef TLineInfo* TLineInfoPtr;
-
-
- struct TFormattingInfo {
- long lineIndex; //input/output
- long nextLineStart; //output
- long lastFormatChar; //input/output
- };
-
- //***************************************************************************************************
-
- class CFormatter : public HandleObject {
- public:
- CFormatter();
-
- void IFormatter();
-
- //•should be called once after IFormatter and before any call to other member of CFormatter
- #ifdef txtnRulers
- void SetHandlers(CStyledText* itsStyledText, CFrames* theFrames, CRulersRanges* rulersRanges, TSize sizeInfo);
- #else
- void SetHandlers(CStyledText* itsStyledText, CFrames* theFrames, TSize sizeInfo);
- #endif
-
- void Free();
- void FreeData(Boolean emptyLine =true);
-
- #ifdef txtnNever
- virtual CFormatter* CreateEmptyClone();
- #endif
-
- OSErr ReserveLines(long extraLines);
-
- void Compact();
-
- inline void DisableFormatting() {--fFormatLevel;}
- inline void EnableFormatting() {++fFormatLevel;}
-
- inline long CountLines() const {return fLastLineIndex+1;}
-
- virtual OSErr Format(long startChar = 0, long endChar = -1, long* firstLine = nil, long* lastLine = nil);
- virtual OSErr ReplaceRange(long offset, long oldLen, long newLen
- , long* firstLine, long* lastLine);
-
- //void RecalcLinesHite(long firstLine, long lastLine);
-
- inline void SetCRFlag(Boolean newFlag) {fCR = newFlag;}
- //"Format" has to be called after calling this meth, crOnly flag overrides the format width.
- inline Boolean GetCRFlag() {return fCR;}
-
- Boolean IsLineFeed(long offset) const;
-
- //••inlines to public some fLineEnds services
- inline long Offset2Line(TOffset lineOffset) const
- {return fLineEnds->Offset2RangeIndex(lineOffset);}
-
- inline long GetLineStart(long lineNo) const {return fLineEnds->GetRangeStart(lineNo);}
- inline long GetLineEnd(long lineNo) const {return fLineEnds->GetRangeEnd(lineNo);}
- void GetLineRange(long lineNo, TOffsetRange* range);
-
- inline Boolean IsLineStart(long offset, long lineNo = -1) const
- {return fLineEnds->IsRangeStart(offset, lineNo);}
- inline Boolean IsLineEmpty(long lineNo) const {return fLineEnds->IsRangeEmpty(lineNo);}
-
- #ifdef txtnDebug
- void CheckCoherence(long count);
- #endif
-
- protected :
- CStyledText* fStyledText;
-
- #ifdef txtnRulers
- CRulersRanges* fRulersRanges;
- #endif
-
- CFrames* fFrames;
- CFrameFormatter* fFrameFormatter;
-
- CRanges* fLineEnds;
-
- CRunsRanges* fRunsRanges;
-
- Boolean fCR;
-
- //note that newLineInfo is not constant, it returns the actual values (which may be modified by a descendent)
- #ifdef txtnMultiFrames
- virtual void SetLineInfo(TLineInfo* newLineInfo, TFormattingInfo* formatInfo, Boolean allowReflow = true);
- #else
- virtual void SetLineInfo(TLineInfo* newLineInfo, TFormattingInfo* formatInfo);
- #endif
-
- virtual OSErr InsertLine(TLineInfo* newLineInfo, TFormattingInfo* formatInfo);
-
- virtual void BreakLine(long startBreak, short formattingWidth, TLineInfo* lineInfo);
-
- virtual short BreakVisibleChars(long lineStart, long runStart, short runLen, Fixed* widthAvail
- , CRunObject* runObj);
-
- virtual short BreakRun(long lineStart, long runStart, short runLen, Fixed* widthAvail
- , CRunObject* runObj);
-
- virtual short BreakCtrlChar(long offset, Fixed* widthAvail);
-
- private:
- short fFormatLevel; //to disable formatting
-
- #ifdef txtnRulers
- CRulerObject* fParagraphRuler;
- #endif
-
- Fixed fLineFormattingWidth;
-
- long fLastLineIndex;
-
- #ifdef txtnAdvRulers
- TPendingTab fPendingTab;
- Fixed fTabMungedWidth;
- #endif
-
- #ifdef txtnMultiFrames
- void CheckFramesReflow(const CFormatReflowLines* reflowInfo
- , TFormattingInfo* formatInfo, long* nextFormatOffset);
- #endif
-
- Boolean AppendEmptyLine();
- OSErr FormatRange(long startChar, long endChar, long* firstLine, long* lastLine);
- OSErr FormatAll();
-
- #ifdef txtnMultiFrames
- void RemoveLines(long firstLine, long count, CFormatReflowLines* reflowInfo);
- long RemoveFormattedLines(long lastFormattedLine, CFormatReflowLines* reflowInfo);
- #else
- void RemoveLines(long firstLine, long count);
- long RemoveFormattedLines(long lastFormattedLine);
- #endif
-
- #ifdef txtnAdvRulers
- short BreakAlignTabChars(long lineStart, long runStart, short runLen, Fixed* widthAvail
- , CRunObject* runObj);
- #endif
-
- void CalcCharsHite(long charsOffset, short charsCount, TLineHiteInfo* lineHiteInfo) const;
- };
- //***************************************************************************************************
-
-
- #endif
-